package com.nzf.vote.model.vo;


import lombok.Data;


/**
 * @author csw
 * @date 2022/3/3
 * @time 13:13
 */

@Data
public class Results {
    private int code;
    private String message;
    private Object data;

    public Results(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Results(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
    public static Results success(){
        return new Results(Status.SUCCESS.getCode(), Status.SUCCESS.getMessage());
    }
    public static Results success(Object data){
        return new Results(Status.SUCCESS.getCode(), Status.SUCCESS.getMessage(), data);
    }

    public enum Status {
        SUCCESS(200, "请求成功"),
        NOTFOUND(404, "资源不存在"),
        SERVERERROR(500, "服务器不可预期错误");
        private int code;
        private String message;

        Status(int code, String message) {
            this.code = code;
            this.message = message;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }
    }
}
